var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

// 用户
var userRouter = require('./routes/user');
// 上传图片
var uploadRouter=require('./routes/upload')
// 入职信息
var EntryMessageRouter=require('./routes/entrymessage')
// 部门
var departmentRouter=require('./routes/department')
// 岗位
var stationRouter=require('./routes/station')
//教育经历
var education_experience=require('./routes/eduction_experience')
// 工作经历
var work_experienceRouter=require('./routes/work_experience')
var dayworkRouter = require('./routes/daywork');
var planRouter = require("./routes/plan");

//资料模块
var means_experienceRouter=require('./routes/means')


var app = express();

// 配置跨域
var cors=require('cors')
app.use(cors())

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/user', userRouter);
app.use('/daywork', dayworkRouter);
app.use('/upload', uploadRouter);
app.use('/department', departmentRouter);
app.use('/station', stationRouter);
app.use('/education_experience', education_experience);
app.use('/work_experience', work_experienceRouter);
app.use('/entryMessage', EntryMessageRouter)
app.use("/plan", planRouter);
app.use('/means',means_experienceRouter)

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
